# Start the Node server in background and record PID to .server.pid
Param(
    [string]$ServerDir = (Get-Location).Path
)
Set-Location -Path $ServerDir

# Start node in background and capture process
$proc = Start-Process -FilePath "node" -ArgumentList "index.js" -WorkingDirectory $ServerDir -PassThru
$pid = $proc.Id
Write-Output "Started node with PID: $pid"

# Save PID to file for later stop
Set-Content -Path "$ServerDir/.server.pid" -Value $pid

Write-Output "PID saved to $ServerDir\.server.pid"
